// profile.js
Page({
  data: {
    userName: '小爱用户',
    orders: [
      { id: 1, date: '2023-05-01', total: 45 },
      { id: 2, date: '2023-05-03', total: 38 }
    ]
  },
  onLoad: function () {
    const app = getApp()
    this.setData({
      userName: app.globalData.userInfo.nickName
    })
  },
  changeUserName: function () {
    wx.showModal({
      title: '修改用户名',
      editable: true,
      placeholderText: this.data.userName,
      success: (res) => {
        if (res.confirm) {
          const newName = res.content
          this.setData({
            userName: newName
          })
          const app = getApp()
          app.globalData.userInfo.nickName = newName
        }
      }
    })
  }
})
